package org.crazyit.activiti_d1._4_DeleteGroup;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.identity.Group;

import java.util.UUID;

public class DeleteGroup {

    public static void main(String[] args) {

        //1. 创建默认的流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        //2. 得到身份服务组件实例
        IdentityService identityService = engine.getIdentityService();

        //3. 调用newGroup() 方法创建Group 实例
        String genId = UUID.randomUUID().toString();
        Group group = identityService.newGroup(genId);

        //4. 保存Group 到数据库
        identityService.saveGroup(group);

        //5. 查询用户组
        System.out.println("保存后用户组数量:" + identityService.createGroupQuery().count());

        //6. 根据ID 删除用户组
        identityService.deleteGroup(genId);

        //7. 再次查询用户组
        System.out.println("删除后用户组数量:" + identityService.createGroupQuery().count());

    }

}
